package com.dtease.agent.sse.server.controller;

import com.dtease.agent.sse.server.model.EventMessage;
import com.dtease.agent.sse.server.service.SseService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import javax.annotation.Resource;

/**
* @description SSE控制器
* @author chentl
* @class SseController
* @package com.dtease.agent.sse.server.controller
* @since 2025/5/4 08:36
*/
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Resource
    private SseService sseService;

    @PostMapping(value = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public ResponseEntity<Flux<EventMessage>> stream(@RequestParam String sessionId) {
        // todo 调用Agent服务端获取sessionId对应的消息流
        return ResponseEntity.ok()
                .contentType(MediaType.TEXT_EVENT_STREAM)
                .body(sseService.getEventStream(sessionId));
    }


}